Ext.require('Ext.layout.container.Border');
Ext.require('Ext.form.field.ComboBox');
Ext.require('Ext.form.FieldSet');
Ext.require('Ext.util.*');
Ext.onReady(function(){
	//Validators
	var valorTeste = /^\d+(\,\d{2}){0,1}$/i;
	Ext.apply(Ext.form.field.VTypes,{
		//vtype: 'valor'
		valor: function(val){
			return valorTeste.test(val);
		},
		valorText: 'valor inv\u00e1lido!',
		valorMask: /[\d|\,]/i,
		
		//vtype: 'senha'
		senha: function(val){
			var senha2 = Ext.getCmp('senha'),
				ret;
			if (senha2.value == val)
				ret = true;
			else
				ret = false;
			return ret;
		},
		senhaText: 'Senha n\u00e3o correspondente!',
		
		//vtype: 'email'
		emailText: 'O email informado deve estar no formato "usuario@exemplo.com"',
		
		//vtype: 'cpf'
		cpf: function(val){
			if (!(val.length == 14 || val.length == 11)) return false;
			val = val.replace('.','').replace('.','').replace('-','');
			if( val == "00000000000" || 
				val == "11111111111" || val == "22222222222" || 
				val == "33333333333" || val == "44444444444" || 
				val == "55555555555" || val == "66666666666" || 
				val == "77777777777" || val == "88888888888" || 
				val == "99999999999")
				return false;
			add = 0;
			for (var i = 0; i < 9; i++)
				add += parseInt(val.charAt(i)) * (10 - i);
			rev = 11 - (add % 11);
			if (rev == 10 || rev == 11)
				rev = 0;
			if (rev != parseInt(val.charAt(9)))
				return false;
			add = 0;
			for (var i = 0; i < 10; i++)
				add += parseInt(val.charAt(i)) * (11 - i);
			rev = 11 - (add % 11);
			if (rev == 10 || rev == 11)
				rev = 0;
			if (rev != parseInt(val.charAt(10)))
				return false;
			return true;
		},
		cpfMask: /^[\d|\.|\-]/i,
		cpfText: 'CPF inv\u00e1lido!'
	});
});


Ext.application({

	name : 'PW',

	appFolder : 'app',

	requires : ['PW.controller.VariaveisUteis'],

	controllers : ['CtrUsuarios', 'PW.controller.CtrEmpresas'],
	
	autoCreateViewport: true

});
